from typing import Dict, Type
from .base import Extractor
from .deployment import DeploymentExtractor
from .service import ServiceExtractor
from .configmap import ConfigMapExtractor
from .statefulset import StatefulSetExtractor
from .secret import SecretExtractor

class ExtractorFactory:
    """提取器工厂类"""
    
    # 注册所有提取器
    _extractors: Dict[str, Type[Extractor]] = {
        "Deployment": DeploymentExtractor,
        "Service": ServiceExtractor,
        "ConfigMap": ConfigMapExtractor,
        "StatefulSet": StatefulSetExtractor,
        "Secret": SecretExtractor,
        # 注册其他提取器
    }
    
    @classmethod
    def register(cls, resource_type: str, extractor_class: Type[Extractor]) -> None:
        """注册新的提取器"""
        cls._extractors[resource_type] = extractor_class
    
    @classmethod
    def create_extractor(cls, resource_type: str) -> Extractor:
        """根据资源类型创建对应的提取器"""
        extractor_class = cls._extractors.get(resource_type)
        
        if extractor_class is None:
            raise ValueError(f"不支持的资源类型: {resource_type}")
        
        return extractor_class()